#! env python
#-*- coding: utf-8 -*-

import requests

# Gitee API Base URL
API_URL = 'https://gitee.com/api/v5'

def add_comment_to_issue(issue_number, comment_body, api_token=None):
    if api_token is None:
        import os
        api_token = os.environ['GITEE_TOKEN']
    headers = { "Authorization": f"token {api_token}", "Content-Type": "application/json" }
    data = { "body": comment_body }
    response = requests.post(f"{API_URL}/issues/{issue_number}/comments", json=data, headers=headers)
    if response.status_code == 201:
        print("添加评论成功:", response.json())
    else:
        print(f"请求失败，状态码：{response.status_code}, 原因: {response.text}")


if __name__ == '__main__':
    # 替换为你要操作的 Issue 编号、API Token 和评论内容
    issue_number = 'YOUR_ISSUE_NUMBER'
    comment_body = "这是一个来自 Python 脚本的评论！"
    add_comment_to_issue(issue_number, comment_body)
